package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //分页查询
    @GetMapping
    public Result selectStudentPage(StudentQueryParam studentQueryParam){
        PageBean pageBean = studentService.selectStudentPage(studentQueryParam);
        return Result.success(pageBean);
    }
    //根据id批量删除
    @DeleteMapping("/{ids}")
    public Result deleteByIds(@PathVariable List<Integer> ids){
        studentService.deleteByIds(ids);
        return Result.success();
    }
    //添加学员
    @PostMapping
    public Result insertStudent(@RequestBody Student student){
        studentService.insertStudent(student);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result selectStudentById(@PathVariable Integer id){
        Student student = studentService.selectById(id);
        return Result.success(student);
    }
    //修改学员
    @PutMapping
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        return Result.success();
    }
    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result updateScore(@PathVariable Integer id , @PathVariable Integer score){
        studentService.updateScore(id,score);
        return Result.success();
    }
}
